<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>111</title>
</head>
<body>
	<form>
		<p>
			用户名:<input id="name" type="text" name="name" value="" />
			<span id="rep"></span>
		</p>
		<p>
			<input type="submit" value="提交" />
		</p>
	</form>
</body>
</html>

<script type="text/javascript">
	var fom = document.getElementsByTagName('form')[0];
	fom.onsubmit = function(){
		var xhr = new XMLHttpRequest();
		var data = 'name=' + document.getElementById('name').value;
		var sp = document.getElementById('rep');
		xhr.onreadystatechange = function(){
			if(this.readyState == 4){
				if(this.responseText == 1){
					sp.innerHTML = 'YES';
				}else{
					sp.innerHTML = 'NO';
				}
			}
		}
		xhr.open('post','3.php',true);
		xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		xhr.send(data);
		return false;
	}
</script>